package edu.unice.simul.vue;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

import edu.unice.simul.controleur.LaunchControleur;

/**
 * Fenêtre de lancement de l'application
 * 
 * @author Romain Ciaccafava
 * 
 */
public class LaunchFrame extends JFrame {
	private static final long serialVersionUID = -7139586522253584081L;

	private LaunchControleur controleur;

	public LaunchFrame(LaunchControleur controleur) {
		this.controleur = controleur;

		build();
	}

	/**
	 * Construit la fenêtre et ajoute les écouteurs
	 */
	private void build() {
		setPreferredSize(new Dimension(250, 300));
		setTitle("Simulateur de foules");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setLayout(new GridLayout(4, 1));

		JButton quickSimulation = new JButton("Simulation rapide");
		JButton initialisation = new JButton("Simulation complète");
		JButton quit = new JButton("Quitter");

		add(new JLabel("Simulateur de foules", JLabel.CENTER));
		add(quickSimulation);
		add(initialisation);
		add(quit);

		quickSimulation.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				controleur.quickSimulation();
			}
		});

		initialisation.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				controleur.initialisation();
			}
		});

		quit.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});

		pack();

		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

		setLocation((screenSize.width - getWidth()) / 2,
				(screenSize.height - getHeight()) / 2);
		setVisible(true);
	}
}
